package com.cpi.cornpp.futuresversions.converter;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;

import com.cpi.cornpp.futuresversions.dto.CornFuturesVersionsDTO;
import com.cpi.cornpp.futuresversions.view.CornFuturesVersionsView;
import com.cpi.cornpp.purchase.program.dto.PurchaseProgramDTO;

/**
 * Corn Futures Versions Converter
 * @author Edgar Joao
 *
 */
public class CornFuturesVersionsConverter {

	/**
	 * Corn Futures Versions Converter View to DTO
	 * @param view
	 * @return
	 */
	public CornFuturesVersionsDTO converterCornFuturesVersionsViewToDTO(CornFuturesVersionsView view){
		CornFuturesVersionsDTO cornFuturesVersionsDTO = null;
		cornFuturesVersionsDTO = new CornFuturesVersionsDTO();
		cornFuturesVersionsDTO.setCornFutureVersionId(view.getCornFutureVersionId());
		cornFuturesVersionsDTO.setCornFutureId(view.getCornFutureId());
		cornFuturesVersionsDTO.setApplicationFuturePeriodVersionId(view.getApplicationFuturePeriodVersionId());
		cornFuturesVersionsDTO.setApplicationFuturePeriodVersionDescription(view.getApplicationFuturePeriodVersionDescription());
		cornFuturesVersionsDTO.setAccountFuturePeriodVersionId(view.getAccountFuturePeriodVersionId());
		cornFuturesVersionsDTO.setAccountFuturePeriodVersionDescription(view.getAccountFuturePeriodVersionDescription());
		cornFuturesVersionsDTO.setReference(view.getReference());
		cornFuturesVersionsDTO.setQuantity(view.getQuantity());
		cornFuturesVersionsDTO.setUnitPrice(view.getUnitPrice());
		cornFuturesVersionsDTO.setPrice(view.getPrice());
		cornFuturesVersionsDTO.setShortDescription(view.getShortDescription());
		cornFuturesVersionsDTO.setFuturePeriodVersionId(view.getFuturePeriodVersionId());
		cornFuturesVersionsDTO.setCornOrigin(view.getCornOrigin());
		return cornFuturesVersionsDTO;
	}
	
	/**
	 * Corn Futures Versions Converter DTO to View
	 * @param dto
	 * @return
	 */
	public CornFuturesVersionsView converterCornFuturesVersionsDtoToView(CornFuturesVersionsDTO dto){
		CornFuturesVersionsView cornFuturesVersionsView = null;
		cornFuturesVersionsView = new CornFuturesVersionsView();
		cornFuturesVersionsView.setCornFutureVersionId(dto.getCornFutureVersionId());
		cornFuturesVersionsView.setCornFutureId(dto.getCornFutureId());
		cornFuturesVersionsView.setApplicationFuturePeriodVersionId(dto.getApplicationFuturePeriodVersionId());
		cornFuturesVersionsView.setApplicationFuturePeriodVersionDescription(dto.getApplicationFuturePeriodVersionDescription());
		cornFuturesVersionsView.setAccountFuturePeriodVersionId(dto.getAccountFuturePeriodVersionId());
		cornFuturesVersionsView.setAccountFuturePeriodVersionDescription(dto.getAccountFuturePeriodVersionDescription());
		cornFuturesVersionsView.setReference(dto.getReference());
		cornFuturesVersionsView.setQuantity(dto.getQuantity());
		cornFuturesVersionsView.setUnitPrice(dto.getUnitPrice());
		cornFuturesVersionsView.setPrice(dto.getPrice());
		cornFuturesVersionsView.setShortDescription(dto.getShortDescription());
		cornFuturesVersionsView.setFuturePeriodVersionId(dto.getFuturePeriodVersionId());
		cornFuturesVersionsView.setCornOrigin(dto.getCornOrigin());
		return cornFuturesVersionsView;
	}
	
		
	/**
	 * Corn Futures Versions Converter List View to DTO 
	 * @param plantDTOs
	 * @return
	 */
	public List convertViews(List futuresVersionsDTOs){
		List futuresVersionsDTO = null;
		futuresVersionsDTO = new ArrayList(0);
		if(!CollectionUtils.isEmpty(futuresVersionsDTOs)){
			Iterator iterator = futuresVersionsDTOs.iterator();
			CornFuturesVersionsDTO dto = null;
			while(iterator.hasNext()){
				dto = (CornFuturesVersionsDTO) iterator.next();
				futuresVersionsDTO.add(dto);
			}
		}
		return futuresVersionsDTO;	
	}
	
	/**
	 * Corn Futures Versions Converter List View to DTO 
	 * @param plantDTOs
	 * @return
	 */
	public List convertViewsToDTO(List futuresVersionsDTOs){
		List futuresVersionsDTO = null;
		futuresVersionsDTO = new ArrayList(0);
		if(!CollectionUtils.isEmpty(futuresVersionsDTOs)){
			Iterator iterator = futuresVersionsDTOs.iterator();
			CornFuturesVersionsDTO dto = null;
			while(iterator.hasNext()){
				dto = (CornFuturesVersionsDTO) iterator.next();
				futuresVersionsDTO.add(converterCornFuturesVersionsDtoToView(dto));
			}
		}
		return futuresVersionsDTO;	
	}
	
	
	/**
	 * Corn Futures Versions Converter List DTO to View
	 * @param plantDTOs
	 * @return
	 */
	public List convertDTOs (List futuresVersionsViews){
		List cornFuturesVersionsView = null;
		cornFuturesVersionsView = new ArrayList(0);
		
		if(!CollectionUtils.isEmpty(futuresVersionsViews)){
			Iterator iterator = futuresVersionsViews.iterator();
			PurchaseProgramDTO dto = null;
			while(iterator.hasNext()){
				dto = (PurchaseProgramDTO) iterator.next();			
				cornFuturesVersionsView.add(dto);
			}
		}
		return cornFuturesVersionsView;
	}
}
